package cn.chengpengper.im.platform.common.exception;

import cn.chengpengper.im.platform.common.model.enums.HttpCode;
import cn.chengpengper.im.platform.common.response.ResponseMessage;
import cn.chengpengper.im.platform.common.response.ResponseMessageFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/*@formatter:off*/

/**
 * ____________________
 * < 神兽护体，永无bug! >
 * --------------------
 *
 * @author huchengpeng
 * @version v1.0.0
 * @date 2024/11/23 17:11
 * @description 异常处理器
 */

/*@formatter:on*/

@ControllerAdvice
public class ImExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ImException.class)
    public ResponseMessage<String> handleIMException(ImException e) {
        return ResponseMessageFactory.getErrorResponseMessage(e.getCode(), e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseMessage<String> handleException(Exception e) {
        return ResponseMessageFactory.getErrorResponseMessage(HttpCode.PROGRAM_ERROR);
    }


}
